﻿

(function () {
	'use strict';
	var MuseumCreater = function (params) {
		var defaults = {
			container: document.body,   //容器
			fov: 100,                    //相机视角，可用于放大和缩小图片
			orientfov: 60,
			isorient: false,
			offsetLongitude: 0,         //经度偏移量，可用于默认展示图片位置
			offsetLatitude: 0,          //纬度偏移量，可用于默认展示图片位置
			supportTouch: true,         //是否支持手指滑动
			touchSpeed: 0.2,
			supportOrient: true,         //是否支持陀螺仪
			orientSpeed: 1,
			onChange() { },
			onOpen() { }
		}
		params = params || {};
		for (var def in defaults) {
			if (typeof params[def] === 'undefined') {
				params[def] = defaults[def];
			}
			else if (typeof params[def] === 'object') {
				for (var deepDef in defaults[def]) {
					if (typeof params[def][deepDef] === 'undefined') {
						params[def][deepDef] = defaults[def][deepDef];
					}
				}
			}
		}
		// Params
		this.params = params;
		this.params.width = params.container.clientWidth;
		this.params.height = params.container.clientHeight;
		switch (window.orientation) {
			case 90:
				this.params.isorient = true;
				break;
			case -90:
				this.params.isorient = true;
				break;
			default:
				this.params.isorient = false;
		}

		this.target = new THREE.Vector3();
		this.lookat = new THREE.Vector3();
		this._fix = {
			lat: params.offsetLatitude || 0,
			lon: params.offsetLongitude || 0,
			isFixed: params.offsetLatitude || params.offsetLongitude
		};
		this.data = this.params.data;
		this._touch = this._orient = {
			lat: 0,
			lon: 0
		};
		this.isAnim = false;
		this._initStage();
		this._initControl();
		this.InitMuseum();
		this._render();
	}

	//初始化场景
	MuseumCreater.prototype._initStage = function () {
		var s = this;
		const { container, width, height } = this.params;
		//renderer
		this.renderer = new THREE.WebGLRenderer();
		this.renderer = new THREE.WebGLRenderer({ antialias: true });
		this.renderer.setPixelRatio(window.devicePixelRatio);
		this.renderer.setSize(width, height);
		this.renderer.shadowMap.enabled = true;
		this.renderer.shadowMap.type = THREE.PCFSoftShadowMap;
		this.canvas = this.renderer.domElement;

		this.labelRenderer = new THREE.CSS3DRenderer();
		this.labelRenderer.setSize(window.innerWidth, window.innerHeight);
		this.labelRenderer.domElement.style.position = 'absolute';
		this.labelRenderer.domElement.style.top = 0;
		container.appendChild(this.labelRenderer.domElement);

		this.isMove = false;



		container.appendChild(this.canvas);
		//scene
		this.scene = new THREE.Scene();
		//camera
		var fov = this.params.fov;
		if (this.params.isorient) fov = this.params.orientfov;

		this.camera = new THREE.PerspectiveCamera(fov, width / height, 1, 10000);

		this.camera.position.set(0, 18.3, 270.8);

		this.group = new THREE.Group();
		this.scene.add(this.group);

		//雾
		var color = new THREE.Color(0xd3e3f4);
		this.scene.fog = new THREE.FogExp2(color, 0.0018);



		//light
		this.light = new THREE.AmbientLight(0xFFFFFF, 1);
		this.scene.add(this.light);

		this.planeTex;
		this.light01;
		this.light02;
		this.light03;
		this.place001;
		this.place005;
		this.ligthArray = new Array;

		this.isStart = true;
		this.isLOAD = false;
		this.isBtn = false;
		this.isMove = false;


		this.model;
		this.curSelectObj
		this.water;
		this.Floor;
		this.Floorh;
		this.post;
		this.postsubface;
		this.LouTi;


		//记录当前两幅作品
		this.id = 0;
		this.id_nearObj = 0;
		this.currentItemID = -1;
		this.currentGroupID = -1;
		this.currentItemID1 = -1;
		this.currentGroupID1 = -1;

		this.mat;
		this.posterMat;
		this.isPhotoframeCreted = false;
		this.count = 0;
		//顶部柱子
		this.mesh1;
		this.mesh2;
		this.mesh3;
		this.LED1;
		this.LED2;
		this.btn;
		this.btn1;

		//文本
		var nameDiv = document.createElement('div');
		nameDiv.name = 'name';
		nameDiv.className = 'label1';
		nameDiv.textContent = "";
		nameDiv.style.marginTop = '-1em';

		var authDiv = document.createElement('div');
		authDiv.name = 'auth';
		authDiv.className = 'label2';
		authDiv.textContent = "";
		authDiv.style.marginTop = '-1em';
		this.nameText = new THREE.CSS3DObject(nameDiv);
		this.authText = new THREE.CSS3DObject(authDiv);

		var nameDiv1 = document.createElement('div');
		nameDiv1.name = 'name';
		nameDiv1.className = 'label1';
		nameDiv1.textContent = "";
		nameDiv1.style.marginTop = '-1em';

		var authDiv1 = document.createElement('div');
		authDiv1.name = 'auth';
		authDiv1.className = 'label2';
		authDiv1.textContent = "";
		authDiv1.style.marginTop = '-1em';
		this.nameText1 = new THREE.CSS3DObject(nameDiv1);
		this.authText1 = new THREE.CSS3DObject(authDiv1);

		//开始显示文字
		this.startTextL;
		this.startTextR;
		//摄像机贴图
		this.cubeCamera;
		this.cubeCamera = new THREE.CubeCamera(1, 1000, 512);
		this.cubeCamera.renderTarget.texture.generateMipmaps = true;
		this.cubeCamera.renderTarget.texture.minFilter = THREE.LinearMipmapLinearFilter;
		this.cubeCamera.renderTarget.texture.mapping = THREE.CubeReflectionMapping;
		//this.cubeCamera.position.set(0, 20, 80);
		this.scene.add(this.cubeCamera);

		this.cubeCamera1;
		this.cubeCamera1 = new THREE.CubeCamera(1, 1000, 512);
		this.cubeCamera1.renderTarget.texture.generateMipmaps = true;
		this.cubeCamera1.renderTarget.texture.minFilter = THREE.LinearMipmapLinearFilter;
		this.cubeCamera1.renderTarget.texture.mapping = THREE.CubeReflectionMapping;
		//this.cubeCamera.position.set(0, 20, 80);
		this.scene.add(this.cubeCamera1);


		//事件监听
		this.mc = new Hammer(container);




		this.mc.on("tap", function (event) {
			if (s.isAnim == false)
				s.onMousedown(event);
		});

		window.addEventListener('resize', this._bindResize = this._onResize.bind(this));


		this.percentComplete;

	};
	//每帧渲染渲染
	MuseumCreater.prototype._render = function () {
		this.update();
		TWEEN.update();
		this.renderer.render(this.scene, this.camera);
		this.labelRenderer.render(this.scene, this.camera);
		this._intFrame = requestAnimationFrame(this._render.bind(this));
	};

	MuseumCreater.prototype._initControl = function () {
		const self = this;
		const config = this.params;
		if (config.supportTouch) {
			let fov;
			this._toucher = new ObritControl({
				container: config.container,
				radius: config.radius,
				deceleration: 0.1,
				onChange(ev) {
					if (ev !== undefined && ev.deltaX !== undefined && ev.deltaY !== undefined) {
						self._fix.lat += ev.deltaY * config.touchSpeed;
						self._fix.lat = Math.max(-50, Math.min(30, self._fix.lat));
						self._fix.lon += ev.deltaX * config.touchSpeed;

					}
				}
			});
		}
		//陀螺仪控制
		if (config.supportOrient) {
			this.enableOrient();
		}

		document.addEventListener('wheel', this._bindMouseWheel = this.onMouseWheel.bind(this), { passive: false });
	};
	MuseumCreater.prototype.enableOrient = function () {
		const self = this;
		const config = this.params;
		this._orienter = new DeviceOrientationControl({
			onChange(ev) {
				if (ev !== undefined && ev.deltaLat !== undefined && ev.deltaLon !== undefined) {
					self._fix.lat += ev.deltaLat * config.orientSpeed;
					self._fix.lat = Math.max(-30, Math.min(50, self._fix.lat));
					self._fix.lon += ev.deltaLon * config.orientSpeed;

				}
			}
		})
	};
	MuseumCreater.prototype.disableOrient = function () {
		this._orienter.destroy();
	};
    /**
     * 鼠标滚轮改变相机焦距
     */
	MuseumCreater.prototype.onMouseWheel = function (event) {
		if (this.params.fov > 120 && event.deltaY > 0) {

		}
		else {
			this.params.fov += event.deltaY * 0.05;
		}
		this._onResize();
	}
	//响应窗口大小调整
	MuseumCreater.prototype._onResize = function () {
		this.params.width = this.params.container.clientWidth;
		this.params.height = this.params.container.clientHeight;

		if (this.params.width || this.params.height) {
			this.renderer.setSize(this.params.width, this.params.height);
			this.labelRenderer.setSize(this.params.width, this.params.height);
			this.camera.aspect = this.params.width / this.params.height;
		}
		switch (window.orientation) {
			case 90:
				this.params.isorient = true;
				break;
			case -90:
				this.params.isorient = true;
				break;
			default:
				this.params.isorient = false;
		}
		var fov = this.params.fov;
		if (this.params.isorient) fov = this.params.orientfov;
		this.camera.fov = fov;

		this.camera.updateProjectionMatrix();

		this.camera.lookAt(this.target);

		this.renderer.render(this.scene, this.camera);

		this.labelRenderer.render(this.scene, this.camera);

	};

	MuseumCreater.prototype.InitMuseum = function () {

		var s = this;

		s.InitScene();

		//球形包围盒
		var geometry = new THREE.SphereBufferGeometry(600, 32, 32);
		var tex = new THREE.TextureLoader().load("Textures/sky/Sky.jpg");
		var material = new THREE.MeshStandardMaterial({
			map: tex,
			side: THREE.DoubleSide
		});
		var mesh = new THREE.Mesh(geometry, material);
		mesh.position.set(0, 0, 0);
		s.scene.add(mesh);

		// Water		
		var waterGeometry = new THREE.PlaneBufferGeometry(300, 300);

		this.water = new THREE.Water(
			waterGeometry,
			{
				textureWidth: 300,
				textureHeight: 300,
				waterNormals: new THREE.TextureLoader().load('Textures/waternormals.jpg', function (texture) {

					texture.wrapS = texture.wrapT = THREE.RepeatWrapping;

				}),

				alpha: 1.0,
				sunDirection: this.light.position.clone().normalize(),
				sunColor: 0xffffff,
				waterColor: 0x001e0f,
				distortionScale: 3.7,
				fog: s.scene.fog !== undefined,
			}
		);
		this.water.position.set(0, -20, 0);
		this.water.rotation.x = - Math.PI / 2;
		this.water.material.uniforms['distortionScale'].value = 2;
		this.water.material.uniforms['size'].value = 0.5;
		this.water.material.uniforms['alpha'].value = 0.96;
		this.water.material.uniforms['sunDirection'].value.copy(this.light.position).normalize();
		this.scene.add(this.water);



	};
	MuseumCreater.prototype.InitScene = function () {
		var s = this;
		//场景模型
		var object;
		//manager
		var i = 0; var j = 0; var p = 0; var q = 0;
		function loadModel() {
			var wallLineMat = new THREE.MeshBasicMaterial({
				map: s.wallLineTex,
				side: THREE.DoubleSide
			});

			var PostMat = new THREE.MeshStandardMaterial({
				map: PostTex,

				side: THREE.DoubleSide
			});
			var UiMat = new THREE.MeshStandardMaterial({
				map: UiTex,
				emission: 0xffffff,
				//color: 0xffffff,
				//shininess: 25,
				transparent: true,
				side: THREE.DoubleSide
			});
			var sceneMat = new THREE.MeshLambertMaterial({
				map: map,
				reflectivity: 1,
				roughness: 0.5,
				metalness: 0.2,
				side: THREE.DoubleSide,
			});

			var FloorMat = new THREE.MeshPhysicalMaterial({
				map: floorTex,
				color: 0x989898,
				roughness: 0.15,
				metalness: 0.1,
				envMap: s.cubeCamera.renderTarget.texture,
			});

			var FloorMat1 = new THREE.MeshPhysicalMaterial({
				map: floorTex1,
				color: 0x989898,
				roughness: 0.15,
				metalness: 0.1,
				envMap: s.cubeCamera1.renderTarget.texture,
				blending: THREE.CustomBlending,
			});

			var HotspotMat = new THREE.MeshBasicMaterial({
				map: hotspotTex,
				transparent: true,
				side: THREE.DoubleSide
			});

			var LEDMat = new THREE.MeshBasicMaterial({
				map: LEDTex,
				transparent: true,
				side: THREE.DoubleSide
			});

			var halfLEDMat = new THREE.MeshBasicMaterial({
				map: LEDTex,
				transparent: true,
				opacity: 0.5,
				side: THREE.DoubleSide
			});

			var btnMat = new THREE.MeshBasicMaterial({
				map: btnTex,
				shininess: 25,
				transparent: true,
				side: THREE.DoubleSide
			});

			var maskMat = new THREE.MeshBasicMaterial({
				map: maskTex,
				transparent: true,
				side: THREE.FrontSide
			});

			var worksMat = new THREE.MeshBasicMaterial({
				map: worksTex,
				side: THREE.DoubleSide
			});

			for (var p = 1; p <= 68; p++) {
				object.traverse(function (child) {
					if (child.name == 'works' + p) {
						if (child.name == "works1") {
							s.startTextL = child;
						}
						if (child.name == "works44") {
							s.startTextR = child;
						}
						child.traverse(function (grandson) {
							child.index = p;
							child.material = worksMat;
							if (grandson.name.indexOf('point') > -1) {
								grandson.material = HotspotMat;
							}

							if (grandson.name.indexOf('Button') > -1) {
								grandson.name = "btn";
								grandson.material = btnMat;
								var scale = new THREE.Vector3(0.8, 0.8, 0.8);
								s.BtnAni(grandson, scale, 1000);
								grandson.visible = false;
							}


							var callbackPainting = function () {
								var w, h, scale;
								var image = WorksTex.image;
								w = image.width;
								h = image.height;
								if (w > h) {
									scale = h / w;
									Post.scale.set(Post.scale.x, Post.scale.y, scale);
								}
								else {
									scale = w / h;
									Post.scale.set(Post.scale.x, scale, Post.scale.z);
								}
							};

							if (grandson.name.indexOf('Work') > -1) {
								var Post;
								Post = grandson;
								var Path = s.data[i].itemlist[j].imageurl;
								var WorksTex = new THREE.TextureLoader().load(Path,
									callbackPainting
								);

								var WorksMat = new THREE.MeshStandardMaterial({
									map: WorksTex,
									side: THREE.DoubleSide
								});

								grandson.material[1] = WorksMat;
								grandson.material[0] = worksMat;

								grandson.traverse(function (mask) {
									if (mask.name.indexOf('mask') > -1)
										mask.material = maskMat;
								});
								child.groupid = i;
								child.itemid = j;
								j++;
								if (j >= s.data[i].itemlist.length) {
									i++;
									j = 0;

								}
								if (i >= s.data.length) {
									i = 0; j = 0;
								}

							}

							if (grandson.name.indexOf('splace') > -1) {
								grandson.name = grandson.name.slice(6);
							}

							if (grandson.name.indexOf('Text') > -1) {
								grandson.visible = false;
							}
						});

					}

				});
			}
			object.traverse(function (child) {
				if (child.name == "LED") {
					child.traverse(function (grandson) {
						if (grandson.name == "LED1") {
							grandson.material = LEDMat;
							s.LED1 = grandson;
						}
						if (grandson.name == "LED2") {
							grandson.material = halfLEDMat;
							s.LED2 = grandson;
						}
					});
				}
				if (child.name.indexOf('mesh') > -1) {

					if (child.name == "mesh_Floor1") {
						child.material = FloorMat;
						s.Floor = child;
					}
					else if (child.name == "mesh_Floor2") {

						child.material = FloorMat1;
						s.Floorh = child;
					}
					else if (child.name == "mesh_Floor3") {

						child.material = FloorMat;
						//s.Floor = child;
					}
					else if (child.name == "mesh9") {
						child.material = sceneMat;
						s.mesh1 = child;
					}
					else if (child.name == "mesh10") {
						child.material = sceneMat;
						s.mesh2 = child;
					}
					else if (child.name == "mesh8") {
						child.material = sceneMat;

						s.postsubface = child;
					}
					else if (child.name == "mesh11") {
						child.material = sceneMat;

						s.mesh3 = child;
					}

					else
						child.material = sceneMat;

				}

				if (child.name.indexOf('wall') > -1) {
					child.material[0] = sceneMat;
					child.material[1] = wallLineMat;
				}

				if (child.name == "hotspot") {
					child.traverse(function (grandson) {
						if (grandson.name.indexOf('ui') > -1) {
							grandson.material = UiMat;
						}
					});
				}


				if (child.name.indexOf('place') > -1) {
					child.material = HotspotMat;
				}


				if (child.name == "post") {
					child.material = PostMat;
					s.post = child;
				}

			});

			object.scale.set(0.1, 0.1, 0.1);
			s.model = object;
			s.scene.add(s.model);
			$("#loading-toast").fadeOut(100);
			s.isLOAD = true;



		}
		var manager = new THREE.LoadingManager(loadModel);
		var textureLoader = new THREE.TextureLoader(manager);
		var map = textureLoader.load('model/futurechurch/Baking-Wall.jpg', function () {
			s.updateCubeMap();
		});

		var floorTex1 = textureLoader.load('model/futurechurch/baking-foolr.jpg', function () {
			s.updateCubeMap1();
		});

		var floorTex = textureLoader.load('model/futurechurch/baking-foolr.jpg', function () {
			s.updateCubeMap();
		});

		//var floorTex = textureLoader.load("model/futurechurch/baking-foolr.jpg");


		//var floorTex1 = textureLoader.load("model/futurechurch/baking-foolr.jpg");


		var PostTex = textureLoader.load("model/futurechurch/Post.jpg");




		var hotspotTex = textureLoader.load("model/futurechurch/热点.png");


		var LEDTex = textureLoader.load("model/futurechurch/LED.png");

		var UiTex = textureLoader.load("model/futurechurch/UI.png");



		var btnTex = textureLoader.load("model/futurechurch/Button.png");


		var maskTex = textureLoader.load("model/futurechurch/mask.png");


		var worksTex = textureLoader.load("model/futurechurch/baking-works.jpg");


		this.wallLineTex = textureLoader.load("model/futurechurch/UV-excursion-.jpg");
		this.wallLineTex.wrapS = THREE.RepeatWrapping;
		this.wallLineTex.wrapT = THREE.RepeatWrapping;
		manager.onProgress = function (item, loaded, total) {

			//console.log(item, loaded, total);

		};

		function onProgress(xhr) {

			if (xhr.lengthComputable) {

				this.percentComplete = xhr.loaded / xhr.total * 100;
				console.log('model ' + Math.round(this.percentComplete, 2) + '% downloaded');
			}

		}

		function onError() { }

		var loader = new THREE.FBXLoader(manager);

		loader.load('model/futurechurch/scene.fbx', function (obj) {

			object = obj;

		}, onProgress, onError);
	}


	//跳转到第groupid组，第itemid个作品
	MuseumCreater.prototype.goto = function (groupid, itemid) {
		//alert(groupid + ":" + itemid);
		var s = this;
		var moveTarget = null;
		if (!s.isMove) {
			this.model.traverse(function (child) {
				if (child.name.indexOf('works') > -1) {
					if (child.groupid == groupid && child.itemid == itemid) {
						if (moveTarget == null) {
							moveTarget = child;
						}
						else if (moveTarget.index > child.index) {
							moveTarget = child;
						}

					}

				}

			});
			moveTarget.traverse(function (grandson) {
				if (grandson.name.indexOf('Work') > -1) {
					s.MoveToPhotoframe(grandson);
					s.currentGroupID = moveTarget.groupid;
					s.currentItemID = moveTarget.itemid;
					s.id = moveTarget.index;
					s.id_nearObj = s.GetNearID();
				}
			});
		}
	}

	////实例画板
	//MuseumCreater.prototype.CreateFBXmodel = function () {
	//	var s = this;


	//	var loader = new THREE.FBXLoader();

	//	var tex = new THREE.TextureLoader().load('model/photoframe/Photo-Albedo.jpg', function () {
	//		s.updateCubeMap();
	//	});

	//	s.mat = new THREE.MeshPhysicalMaterial({
	//		map: tex,
	//		bumpMap: tex,
	//		bumpScale: 0.3,
	//		side: THREE.DoubleSide
	//	});

	//	var postertex = new THREE.TextureLoader().load('model/photoframe/poster.jpg', function () {
	//		s.updateCubeMap();
	//	});

	//	s.posterMat = new THREE.MeshPhongMaterial({
	//		map: postertex,
	//		shininess: 25,
	//		side: THREE.DoubleSide
	//	});


	//	var hotspot = new THREE.TextureLoader().load("model/scene/hotspot.png");
	//	var Hotspotmaterial = new THREE.MeshBasicMaterial({
	//		map: hotspot,
	//		blending: THREE.AdditiveBlending,
	//		side: THREE.DoubleSide
	//	});
	//	Hotspotmaterial.transparent = true;
	//	Hotspotmaterial.opacity = 0.5;


	//	var initAngle = 90;
	//	var rad = 240;
	//	var h = 1.5;
	//	var angleOffse = 13;
	//	var add = (180 - angleOffse * 2) / 11;


	//	loader.load('model/photoframe/photoframe.fbx', function (obj) {
	//		for (var i = 0; i < s.data.length; i++) {
	//			for (var j = 0; j < s.data[i].itemlist.length; j++) {
	//				if (initAngle == 90 /*|| initAngle == 180 || initAngle == 90 || initAngle == 270*/) {
	//					initAngle += angleOffse;
	//				}
	//				if (initAngle == 270 - angleOffse + add /*|| initAngle == 360 || initAngle == 90 || initAngle == 270*/) {
	//					initAngle = 270 + angleOffse;
	//				}

	//				if (initAngle == 450 - angleOffse + add) {
	//					rad = 130;
	//					h = -11.5;
	//					angleOffse = 20;
	//					initAngle = 90 + angleOffse;
	//					add = (180 - angleOffse * 2) / 7
	//				}

	//				var object = obj.clone();
	//				var Path = s.data[i].itemlist[j].imageurl;

	//				var postertex = new THREE.TextureLoader().load(Path);
	//				s.posterMat = new THREE.MeshPhongMaterial({
	//					map: postertex,
	//					shininess: 25,
	//					side: THREE.DoubleSide
	//				});

	//				object.traverse(function (child) {

	//					if (child.isMesh) {

	//						child.material = s.mat;
	//						child.castShadow = true;
	//						child.receiveShadow = true;
	//						if (child.name == "Photo_frame") {
	//							child.material = Hotspotmaterial;

	//						}
	//						if (child.name == "Photo-1" || child.name == "Photo-2"/*||child.name == "works-02"*//*||child.name == "works-02001"*/) {
	//							child.material = s.posterMat;

	//						}

	//						if (child.name == "btn-1" || child.name == "btn-2"/*||child.name == "works-02"*//*||child.name == "works-02001"*/) {
	//							var tex = new THREE.TextureLoader().load("model/photoframe/按钮.png");
	//							var CircleMat = new THREE.MeshPhongMaterial({
	//								map: tex,
	//								shininess: 25,
	//								transparent: true,
	//								side: THREE.DoubleSide
	//							});
	//							child.material = CircleMat;
	//							CircleMat.opacity = 0;
	//						}


	//					}
	//				});

	//				var x = 0 + (rad * Math.cos((initAngle / 180) * Math.PI));
	//				var z = 0 + (rad * Math.sin((initAngle / 180) * Math.PI));

	//				object.name = "photoframe";
	//				object.scale.set(0.1, 0.1, 0.1);
	//				object.groupid = i;
	//				object.itemid = j;
	//				object.position.set(x, h, z);
	//				object.lookAt(2 * x, h, 2 * z);

	//				object.rotateY(Math.sign(object.position.x) * Math.sign(object.position.z) * - Math.PI / 6);
	//				//按钮
	//				var tex = new THREE.TextureLoader().load("model/photoframe/Button.png");
	//				var CircleMat = new THREE.MeshPhongMaterial({
	//					map: tex,
	//					shininess: 25,
	//					transparent: true,
	//					side: THREE.DoubleSide
	//				});


	//				var Circle = new THREE.Mesh(new THREE.CircleBufferGeometry(10, 100, 0, Math.PI * 2), CircleMat);
	//				Circle.visible = false;
	//				Circle.name = "btn";
	//				Circle.position.set(0, 20, 20);
	//				Circle.userData = { URL: "https://www.baidu.com/" };
	//				object.add(Circle);
	//				s.group.add(object);

	//				initAngle += add;

	//				if (j == s.data[i].itemlist.length - 1 && i == s.data.length - 1) {
	//					s.isPhotoframeCreted = true;
	//				}

	//			}
	//		}


	//	});

	//	var object;

	//}

	MuseumCreater.prototype.GetNearID = function () {
		var id = this.curSelectObj.name.slice(5);
		if (id % 2 == 0) {
			if (id == "68") {
				var id = 25;
			}
			else if (id == "24") {
				var id = 1;
			}
			else {
				var id = parseInt(id) + 1;
			}

		}
		else {
			if (id == "25") {
				var id = 68;
			}
			else if (id == "1") {
				var id = 24;
			}
			else {
				var id = parseInt(id) - 1;
			}

		}
		return id;
	}
	MuseumCreater.prototype.GetNearObj = function () {
		var id = this.curSelectObj.name.slice(5);
		var obj = this.curSelectObj;
		if (id % 2 == 0) {
			if (id == "68") {
				var id = 25;
			}
			else if (id == "24") {
				var id = 1;
			}
			else {
				var id = parseInt(id) + 1;
			}

			this.model.traverse(function (child) {
				if (child.name == "works" + id) {
					obj = child;
				}
			});
		}
		else {
			if (id == "25") {
				var id = 68;
			}
			else if (id == "1") {
				var id = 24;
			}
			else {
				var id = parseInt(id) - 1;
			}
			this.model.traverse(function (child) {
				if (child.name == "works" + id) {
					obj = child;
				}
			});
		}
		return obj;
	}
	MuseumCreater.prototype.updateCubeMap = function () {

		var s = this;
		if (s.isLOAD) {
			//s.Floor.visible = false;

			var worldPosition = new THREE.Vector3();

			s.camera.getWorldPosition(worldPosition);
			worldPosition.y = - worldPosition.y - 24;
			s.cubeCamera.position.copy(worldPosition);

			//s.Floor.visible = true;

			s.cubeCamera.update(s.renderer, s.scene);
		}

	}
	MuseumCreater.prototype.updateCubeMap1 = function () {
		var s = this;
		if (s.isLOAD) {
			s.Floorh.visible = false;

			var worldPosition1 = new THREE.Vector3();

			s.camera.getWorldPosition(worldPosition1);
			worldPosition1.y = - worldPosition1.y - 2;
			s.cubeCamera1.position.copy(worldPosition1);

			//wallMat.roughness = 0.6;

			s.Floorh.visible = true;

			s.cubeCamera1.update(s.renderer, s.scene);
		}

	}
	MuseumCreater.prototype.getIntersects = function (event) {
		var s = this;
		event.preventDefault();

		// 声明 raycaster 和 mouse 变量
		var raycaster = new THREE.Raycaster();
		var mouse = new THREE.Vector2();

		// 通过鼠标点击位置,计算出 raycaster 所需点的位置,以屏幕为中心点,范围 -1 到 1
		mouse.x = (event.center.x / window.innerWidth) * 2 - 1;
		mouse.y = -(event.center.y / window.innerHeight) * 2 + 1;


		//通过鼠标点击的位置(二维坐标)和当前相机的矩阵计算出射线位置
		raycaster.setFromCamera(mouse, this.camera);

		// 获取与射线相交的对象数组，其中的元素按照距离排序，越近的越靠前
		var intersects = raycaster.intersectObject(s.scene, true);

		//返回选中的对象
		return intersects;
	}

	MuseumCreater.prototype.getClickIntersects = function (event) {
		var s = this;
		event.preventDefault();



		// 声明 raycaster 和 mouse 变量
		var raycaster = new THREE.Raycaster();
		var mouse = new THREE.Vector2();

		// 通过鼠标点击位置,计算出 raycaster 所需点的位置,以屏幕为中心点,范围 -1 到 1
		mouse.x = (event.center.x / window.innerWidth) * 2 - 1;
		mouse.y = -(event.center.y / window.innerHeight) * 2 + 1;


		//通过鼠标点击的位置(二维坐标)和当前相机的矩阵计算出射线位置
		raycaster.setFromCamera(mouse, this.camera);

		// 获取与射线相交的对象数组，其中的元素按照距离排序，越近的越靠前
		var intersects = raycaster.intersectObjects(s.scene.children, true);

		//返回选中的对象
		return intersects;
	}

	//移动到热点
	MuseumCreater.prototype.MoveIndexMesh = function (selectObject) {
		var s = this;
		s.isBtn = false
		if (s.btn instanceof THREE.Mesh) {
			s.btn1.visible = false;
			s.btn.visible = false;
		}
		s.id = 0;
		s.id_nearObj = 0;
		s.nameText.element.hidden = true;
		s.authText.element.hidden = true;
		var worldPosition = new THREE.Vector3();

		selectObject.getWorldPosition(worldPosition);
		console.log(worldPosition);
		var lengthPos = new THREE.Vector3();
		lengthPos.x = worldPosition.x - this.camera.position.x;
		lengthPos.y = worldPosition.y + 17 - this.camera.position.y;
		lengthPos.z = worldPosition.z - this.camera.position.z;
		var movespeed = 0.2;
		var moveTime = lengthPos.length() / movespeed;
		worldPosition.y = worldPosition.y + 17;

		this.CamMoveTo(worldPosition, moveTime);


		var TarWorldPos = new THREE.Vector3();
		TarWorldPos.x = 2 * worldPosition.x - this.camera.position.x;
		TarWorldPos.y = worldPosition.y + 17;
		TarWorldPos.z = 2 * worldPosition.z - this.camera.position.z;
		this.TargetMoveTo(TarWorldPos, moveTime);
		console.log(TarWorldPos);
	}

	//移动到指定相框
	MuseumCreater.prototype.MoveToPhotoframe = function (selectObject) {
		var s = this;
		//如果是当前站位
		if (selectObject.parent.index != s.id_nearObj && selectObject.parent.index != s.id) {
			s.isBtn = true;
			if (s.btn instanceof THREE.Mesh && s.btn1 instanceof THREE.Mesh) {
				s.btn.visible = false;
				s.btn1.visible = false;
			}
			s.nameText.element.hidden = true;
			s.authText.element.hidden = true;
			s.nameText1.element.hidden = true;
			s.authText1.element.hidden = true;
			s.nameText.scale.x = 0;
			s.nameText.scale.y = 0;
			s.nameText.scale.z = 0;

			s.authText.scale.x = 0;
			s.authText.scale.y = 0;
			s.authText.scale.z = 0;

			s.nameText1.scale.x = 0;
			s.nameText1.scale.y = 0;
			s.nameText1.scale.z = 0;

			s.authText1.scale.x = 0;
			s.authText1.scale.y = 0;
			s.authText1.scale.z = 0;
		}

		var LookAt;
		selectObject.parent.traverse(function (child) {
			if (child.name.indexOf('place') > -1)
				selectObject = child;

			if (child.name == "btn") {
				s.curSelectObj = child.parent;

			}

			if (child.name.indexOf('Work') > -1) {
				LookAt = child;

			}

		});


		var worldPosition = new THREE.Vector3();
		selectObject.getWorldPosition(worldPosition);
		var lengthPos = new THREE.Vector3();
		lengthPos.x = worldPosition.x - this.camera.position.x;
		lengthPos.y = worldPosition.y - this.camera.position.y;
		lengthPos.z = worldPosition.z - this.camera.position.z;
		var movespeed = 0.15;
		var moveTime = lengthPos.length() / movespeed;
		worldPosition.y = worldPosition.y + 17;


		var TarWorldPos = new THREE.Vector3();
		LookAt.getWorldPosition(TarWorldPos);

		TarWorldPos.x = TarWorldPos.x;
		TarWorldPos.y = TarWorldPos.y + 10;
		TarWorldPos.z = TarWorldPos.z;
		if (moveTime < 800) {
			moveTime = 800;
		}
		this.CamMoveTo(worldPosition, moveTime);
		this.TargetMoveTo(TarWorldPos, moveTime * 0.8);
		this.params.onChange(selectObject.parent.groupid, selectObject.parent.itemid);
	}
	MuseumCreater.prototype.MoveToPhotoframeP = function (selectObject) {
		var s = this;
		//如果当前站位
		if (selectObject.index != s.id_nearObj && selectObject.index != s.id) {
			s.isBtn = true;
			if (s.btn instanceof THREE.Mesh && s.btn1 instanceof THREE.Mesh) {
				s.btn.visible = false;
				s.btn1.visible = false;
			}
			s.nameText.element.hidden = true;
			s.authText.element.hidden = true;
			s.nameText1.element.hidden = true;
			s.authText1.element.hidden = true;
			s.nameText.scale.x = 0;
			s.nameText.scale.y = 0;
			s.nameText.scale.z = 0;

			s.authText.scale.x = 0;
			s.authText.scale.y = 0;
			s.authText.scale.z = 0;

			s.nameText1.scale.x = 0;
			s.nameText1.scale.y = 0;
			s.nameText1.scale.z = 0;

			s.authText1.scale.x = 0;
			s.authText1.scale.y = 0;
			s.authText1.scale.z = 0;
		}

		var LookAt, place;
		selectObject.traverse(function (child) {
			if (child.name.indexOf('place') > -1)
				place = child;

			if (child.name == "btn") {
				s.curSelectObj = child.parent;

			}

			if (child.name.indexOf('Work') > -1) {
				LookAt = child;

			}

		});


		var worldPosition = new THREE.Vector3();
		//s.scene.updateMatrixWorld(true);
		place.getWorldPosition(worldPosition);
		var lengthPos = new THREE.Vector3();
		lengthPos.x = worldPosition.x - this.camera.position.x;
		lengthPos.y = worldPosition.y - this.camera.position.y;
		lengthPos.z = worldPosition.z - this.camera.position.z;
		var movespeed = 0.15;
		var moveTime = lengthPos.length() / movespeed;
		worldPosition.y = worldPosition.y + 17;


		var TarWorldPos = new THREE.Vector3();
		//s.scene.updateMatrixWorld(true);
		LookAt.getWorldPosition(TarWorldPos);

		TarWorldPos.x = TarWorldPos.x;
		TarWorldPos.y = TarWorldPos.y + 10;
		TarWorldPos.z = TarWorldPos.z;
		if (moveTime < 800) {
			moveTime = 800;
		}
		this.CamMoveTo(worldPosition, moveTime);
		this.TargetMoveTo(TarWorldPos, moveTime * 0.8);
	}
	MuseumCreater.prototype.needMove = function (selectObject) {
		var s = this;
		if (selectObject.index != s.id && selectObject.index != s.id_nearObj)
			return true;

		var projector = new THREE.Projector();

		var world_vector = new THREE.Vector3(0, 0, 1);
		selectObject.getWorldPosition(world_vector);
		var vector = world_vector.project(this.camera)
		var halfWidth = window.innerWidth / 2;
		var halfHeight = window.innerHeight / 2;
		var screenPos = new THREE.Vector2();


		screenPos.x = Math.round(vector.x * halfWidth + halfWidth);
		screenPos.y = Math.round(-vector.y * halfHeight + halfHeight);

		var offset = 100;
		if (Math.abs(screenPos.x - halfWidth) < offset) {
			//alert("范围内");
			return true;
		}

		if (Math.abs(screenPos.x - halfWidth) > offset) {
			//alert("范围外");
			return false;
		}

	};
	//单击事件
	MuseumCreater.prototype.onMousedown = function (event) {
		var s = this;
		if (!s.isMove) {
			// 获取 raycaster 和所有模型相交的数组，其中的元素按照距离排序，越近的越靠前
			var intersects = s.getClickIntersects(event);
			var selectObject;
			// 获取选中最近的 Mesh 对象
			if (intersects.length != 0 && intersects[0].object instanceof THREE.Mesh) {
				selectObject = intersects[0].object;
				//点击按钮打开链接
				if (selectObject.name == "btn" && selectObject.material.visible) {
					s.params.onOpen(selectObject.parent.groupid, selectObject.parent.itemid);
					//window.open(s.data[selectObject.parent.groupid].itemlist[selectObject.parent.itemid].detail);
				}
				//点击当前站位的两个画板之外的画板主体
				if (selectObject.name.indexOf('works') > -1) {
					if (selectObject.index != s.id && selectObject.index != s.id_nearObj) {
						selectObject.traverse(function (child) {
							if (child.name.indexOf('Work') > -1) {
								selectObject = child;
							}
						});
						s.MoveToPhotoframe(selectObject);
						s.currentGroupID = selectObject.parent.groupid;
						s.currentItemID = selectObject.parent.itemid;
						s.id = selectObject.parent.index;
						s.id_nearObj = s.GetNearID();
					}
					else {
						if (!s.needMove(selectObject)) {
							selectObject.traverse(function (child) {
								if (child.name.indexOf('Work') > -1) {
									selectObject = child;
								}
							});
							s.MoveToPhotoframe(selectObject);
							s.currentGroupID = selectObject.parent.groupid;
							s.currentItemID = selectObject.parent.itemid;
							s.id = selectObject.parent.index;
							s.id_nearObj = s.GetNearID();
						}
					}
				}
				//点击到画板子物体
				else if (selectObject.parent.name.indexOf('works') > -1) {
					if (s.needMove(selectObject.parent)) {
						//点击到当前站位的画板的作品
						if (selectObject.parent.index == s.id && selectObject.name.indexOf('Work') > -1) {
							s.params.onOpen(selectObject.parent.groupid, selectObject.parent.itemid);
							//window.open(s.data[selectObject.parent.groupid].itemlist[selectObject.parent.itemid].detail);
						}
						else if (selectObject.parent.index == s.id_nearObj && selectObject.name.indexOf('Work') > -1) {
							s.params.onOpen(s.GetNearObj().groupid, s.GetNearObj().itemid);
							//window.open(s.data[s.GetNearObj().groupid].itemlist[s.GetNearObj().itemid].detail);
						}
						//点击到当前站位的画板之外的子物体
						else {
							s.MoveToPhotoframe(selectObject);
							s.currentGroupID = selectObject.parent.groupid;
							s.currentItemID = selectObject.parent.itemid;
							s.id = selectObject.parent.index;
							s.id_nearObj = s.GetNearID();

						}
					}
					else {
						s.MoveToPhotoframe(selectObject);
						s.currentGroupID = selectObject.parent.groupid;
						s.currentItemID = selectObject.parent.itemid;
						s.id = selectObject.parent.index;
						s.id_nearObj = s.GetNearID();
					}


				}

				else if (selectObject.name.indexOf('place') > -1) {
					s.MoveIndexMesh(selectObject);
				}

				var Obj7, Obj8, Obj6, Obj5;
				s.model.traverse(function (child) {
					if (child.name == "works22") {
						Obj7 = child;
					}
					if (child.name == "works23") {
						Obj6 = child;
					}
					if (child.name == "works1") {
						Obj8 = child;
					}
					if (child.name == "works44") {
						Obj5 = child;
					}
				});
				if (selectObject.name == "ui-7") {

					s.MoveToPhotoframeP(Obj7);
				}
				else if (selectObject.name == "ui-8") {
					s.MoveToPhotoframeP(Obj8);
				}
				else if (selectObject.name == "ui-6") {
					s.MoveToPhotoframeP(Obj6);
				}
				else if (selectObject.name == "ui-5") {
					s.MoveToPhotoframeP(Obj5);
				}


			} else {
				//alert("未选中 Mesh!");
			}

		}
	}



	//按键显示
	MuseumCreater.prototype.ShowBtn = function (selectObject) {
		var s = this;
		var text;

		selectObject.traverse(function (child) {

			if (child.name == "btn") {
				s.btn = child;
				child.visible = true;
				s.isBtn = false;

			}
			if (child.name.indexOf('Text') > -1) {
				text = child;
			}


		});
		s.nameText.element.hidden = false;
		s.authText.element.hidden = false;

		var name = this.data[selectObject.groupid].itemlist[selectObject.itemid].name;
		var auth = this.data[selectObject.groupid].itemlist[selectObject.itemid].author;


		s.nameText.element.textContent = name;

		s.nameText.position.set(-135, 0, -500);
		//s.nameText.scale.set(0, 0, 0);

		//s.nameText.element.hidden = false;
		text.add(s.nameText);
		s.nameText.rotation.set(0, 0, -Math.PI / 2);


		s.authText.element.textContent = auth;

		s.authText.position.set(-155, 0, -500);
		//s.authText.scale.set(0, 0, 0);
		//s.authText.element.hidden = false;
		text.add(s.authText);
		s.authText.rotation.set(0, 0, -Math.PI / 2);
		var scale = new THREE.Vector3(1, 1, 1);
		this.TextAni(s.nameText, scale, 500);
		this.TextAni(s.authText, scale, 500);


	}

	//按键显示
	MuseumCreater.prototype.ShowBtn1 = function (selectObject) {
		var s = this;
		var text;

		s.nameText1.element.hidden = false;
		s.authText1.element.hidden = false;
		selectObject.traverse(function (child) {

			if (child.name == "btn") {
				s.btn1 = child;
				child.visible = true;
				//s.isBtn = false;

			}
			if (child.name.indexOf('Text') > -1) {
				text = child;
			}


		});;
		var name = this.data[selectObject.groupid].itemlist[selectObject.itemid].name;
		var auth = this.data[selectObject.groupid].itemlist[selectObject.itemid].author;


		s.nameText1.element.textContent = name;

		s.nameText1.position.set(-133, 0, -500);

		//s.nameText1.element.hidden = false;
		text.add(s.nameText1);
		s.nameText1.rotation.set(0, 0, -Math.PI / 2);


		s.authText1.element.textContent = auth;

		s.authText1.position.set(-155, 0, -500);

		//s.authText1.element.hidden = false;
		text.add(s.authText1);
		s.authText1.rotation.set(0, 0, -Math.PI / 2);
		var scale = new THREE.Vector3(1, 1, 1);
		this.TextAni(s.nameText1, scale, 500);
		this.TextAni(s.authText1, scale, 500);
	}

	MuseumCreater.prototype.CamMoveTo = function (position, time) {
		this.isAnim = true;
		var s = this;
		s.isMove = true;
		var tween = new TWEEN.Tween(this.camera.position);
		tween.to(position, time || 2000);
		tween.easing(TWEEN.Easing.Quadratic.Out);
		tween.start();
		tween.onComplete(this.AnimEnd.bind(this));
	};
	MuseumCreater.prototype.TextAni = function (text, scale, time) {
		var s = this;

		var tween = new TWEEN.Tween(text.scale);
		tween.to(scale, time || 2000).onUpdate(function (object) {


		});

		tween.easing(TWEEN.Easing.Quadratic.InOut);
		tween.start();

	};
	MuseumCreater.prototype.BtnAni = function (obj, scale, time) {
		var s = this;

		var tween = new TWEEN.Tween(obj.scale);
		tween.to(scale, time || 2000).onUpdate(function (object) {

		});
		tween.repeat(Infinity);
		tween.yoyo(true);
		tween.easing(TWEEN.Easing.Quadratic.InOut);
		tween.start();

	};
	MuseumCreater.prototype.TargetMoveTo = function (position, time) {
		this.isAnim = true;
		new TWEEN.Tween(this.target).to(position, time || 2000).easing(TWEEN.Easing.Quadratic.Out).start();

	};
	MuseumCreater.prototype.AnimEnd = function () {
		var s = this;
		this.isAnim = false;
		s.isMove = false;
		var CamPos = this.camera.position;
		//this.camera.getWorldPosition(CamPos);
		var lookat = new THREE.Vector3();

		lookat.x = this.target.x - CamPos.x;
		lookat.y = this.target.y - CamPos.y;
		lookat.z = this.target.z - CamPos.z;
		if (lookat.x > 0) {
			var lon = Math.atan(lookat.z / lookat.x) * 180 / Math.PI;
			var lat = Math.asin(lookat.y / lookat.length()) * 180 / Math.PI;
			this._fix = { lat: lat - this._orient.lat, lon: lon - this._orient.lon }
		}
		else if (lookat.x < 0) {
			var lon = Math.atan(lookat.z / lookat.x) * 180 / Math.PI - 180;
			var lat = Math.asin(lookat.y / lookat.length()) * 180 / Math.PI;
			this._fix = { lat: lat - this._orient.lat, lon: lon - this._orient.lon }
		}
		else {
			var lon = 90;
			var lat = Math.asin(lookat.y / lookat.length()) * 180 / Math.PI;
			this._fix = { lat: lat - this._orient.lat, lon: lon - this._orient.lon }
		}

		//显示按键
		if (s.isBtn) {
			this.ShowBtn(this.curSelectObj);
			var id = this.curSelectObj.name.slice(5);
			if (id % 2 == 0) {
				if (id == "68") {
					var id = 25;
				}
				else if (id == "24") {
					var id = 1;
				}
				else {
					var id = parseInt(id) + 1;
				}

				this.model.traverse(function (child) {
					if (child.name == "works" + id) {
						s.ShowBtn1(child);
					}
				});
			}
			else {
				if (id == "25") {
					var id = 68;
				}
				else if (id == "1") {
					var id = 24;
				}
				else {
					var id = parseInt(id) - 1;
				}
				this.model.traverse(function (child) {
					if (child.name == "works" + id) {
						s.ShowBtn1(child);
					}
				});
			}
		}

	};
	//每帧更新脚本
	MuseumCreater.prototype.update = function () {
		var s = this;
		if (!this.isAnim) {
			let lat = this._fix.lat;
			let lon = this._fix.lon;

			lat = Math.max(-50, Math.min(30, lat));

			lat = THREE.Math.degToRad(lat);
			lon = THREE.Math.degToRad(lon);

			var CamPos = new THREE.Vector3();
			this.camera.getWorldPosition(CamPos);
			this.target.x = 500 * Math.cos(lat) * Math.cos(lon) + CamPos.x;
			this.target.y = 500 * Math.sin(lat) + CamPos.y;
			this.target.z = 500 * Math.cos(lat) * Math.sin(lon) + CamPos.z;
		}


		this.camera.lookAt(this.target);
		this.camera.updateProjectionMatrix();


		if (this.isAnim == true) {
			if (this.curSelectObj.index < 45) {
				this.updateCubeMap1();
			}
			else {
				this.updateCubeMap();
			}


		}
		else {
			if (this.isLOAD) {
				this.water.material.uniforms['time'].value += 1.0 / 60.0;
				this.mesh1.rotation.z += 0.001;
				this.mesh2.rotation.z -= 0.002;
				this.mesh3.rotation.z += 0.002;
				this.LED1.rotation.z += 0.003;
				this.LED2.rotation.z += 0.003;
				this.post.rotation.z += 0.001;
				this.postsubface.rotation.z += 0.001;
				//this.wallLineTex.offset.y -= 0.001;
			}
		}
		if (this.isLOAD) {
			//this.water.material.uniforms['time'].value += 1.0 / 60.0;
			//this.mesh1.rotation.z += 0.001;
			//this.mesh2.rotation.z -= 0.002;
			//this.mesh3.rotation.z += 0.002;
			//this.LED1.rotation.z += 0.003;
			//this.LED2.rotation.z += 0.003;
			//this.post.rotation.z += 0.001;
			//this.postsubface.rotation.z += 0.001;
			this.wallLineTex.offset.y -= 0.001;
		}
		//开始执行
		if (this.isStart) {
			if (this.isLOAD) {

				this.updateCubeMap();
				this.updateCubeMap1();
				s.ShowBtn(this.startTextL)


				s.ShowBtn1(this.startTextR)


				this.isStart = false;
			}
		}
	};

	window.MuseumCreater = MuseumCreater;
})(window);



document.body.addEventListener('touchmove', function (evt) {
	evt.preventDefault();
}, { passive: false });
function getQueryString(name) {
	var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
	var r = window.location.search.substr(1).match(reg);
	if (r != null) {
		return unescape(r[2]);
	}
	return null;
}
function hidMenu() {
	$(".weui-tabbar").fadeOut(100);
	$(".icon_back").fadeOut(100);
}
function showMenu() {
	$(".weui-tabbar").fadeIn(100);
	$(".icon_back").fadeIn(100);
}
$(document).ready(function () {
	var maincontent = new Swiper('.framepage', {
		speed: 700,
		initialSlide: 0,
		observer: true,
		observerParents: true,
	});

	var control, bottom_thumb, bottom_albums;
	var supportOrient = false;
	var ua = navigator.userAgent.toLowerCase();
	if (ua.match(/Android/i) == "android") {
		supportOrient = true;
	}
	else if (ua.match(/iPhone/i) == "iphone") {
		supportOrient = false;
		$(".bottom_icon_device").toggleClass("bottom_icon_fade");
	} else {
		$(".bottom_icon_device").fadeOut(0);
		$("#device_tips").fadeOut(0);
	}
	$.post("https://www.tioyotech.com/artmuseum/api.ashx", { wid: 309, type: "worklist" }, function (res) {
		var data = res;
		control = new MuseumCreater({
			container: document.getElementById('museum'),
			data: data,
			fov: 80,
			orientfov: 50,
			offsetLongitude: -90,
			offsetLatitude: 0,
			supportTouch: true,         //是否支持手指滑动
			supportOrient: supportOrient,     //是否支持陀螺仪
			onChange(groupid, itemid) {
				bottom_albums.slideTo($("#" + data[groupid].itemlist[itemid].id).attr("data-id"));
			},
			onOpen(groupid, itemid) {
				$(".icon_back").fadeIn(100);
				$(".weui-tabbar").fadeIn(100);
				$(".tabbar_work").addClass("tabbar_work_on");
				$("#workdetail").attr("src", "workinfo.aspx?wid=309&mid=" + data[groupid].itemlist[itemid].id);
				$("#authordetail").attr("src", "author.aspx?wid=309&sid=" + data[groupid].itemlist[itemid].authorid);
				maincontent.slideTo(1);
			}
		});

		var index = 0;
		for (var i = 0; i < data.length; i++) {
			$(".left_menu").append('<div class="content ' + (index == 0 ? 'content_on' : '') + '" data-id="' + index + '"><div class="select_icon"></div><div class="item_name">' + data[i].groupname + '</div><div class="item_count">' + data[i].itemlist.length + '</div>');
			for (var j = 0; j < data[i].itemlist.length; j++) {
				$(".bottom_index-wrap").append('<div class="swiper-slide" data-groupid="' + i + '" data-itemid="' + j + '"></div>');
				$(".bottom_thumb-wrap").append('<div class="swiper-slide bottom-content-item" id="' + data[i].itemlist[j].id + '" data-groupid="' + i + '" data-itemid="' + j + '" data-id="' + index + '" style="background-image:url(' + data[i].itemlist[j].thumburl + ');" ></div>');
				index++;
			}
		}
		bottom_thumb = new Swiper('.bottom_thumb', {
			slidesPerView: 'auto',
			spaceBetween: 10,
			initialSlide: 0,
			observer: true,//修改swiper自己或子元素时，自动初始化swiper
			observeParents: true,//修改swiper的父元素时，自动初始化swiper
			freeMode: true,
			passiveListeners: false,
			watchSlidesVisibility: true,
			watchSlidesProgress: true,
		});
		bottom_albums = new Swiper('.bottom_index', {
			slidesPerView: 'auto',
			observer: true,//修改swiper自己或子元素时，自动初始化swiper
			observeParents: true,//修改swiper的父元素时，自动初始化swiper
			navigation: {
				nextEl: '.bottom_icon_next',
				prevEl: '.bottom_icon_prev',
				disabledClass: 'bottom_icon_fade'
			},
			thumbs: {
				swiper: bottom_thumb,
			},
			on: {
				init: function () {
					$(".bottom-content").fadeOut(0);
				},
				slideChange: function () {
					control.goto(this.slides[this.activeIndex].dataset.groupid, this.slides[this.activeIndex].dataset.itemid);
				}
			}
		});
		maincontent.allowTouchMove = false;

	});
	$(".icon_back").on('click', function () {
		$(".icon_back").fadeOut(100);
		$(".weui-tabbar").fadeOut(100);
		$("#workdetail").attr("src", "");
		$("#authordetail").attr("src", "");
		maincontent.slideTo(0);
	});
	$("#defaut").on('click', function () {
		window.location.href = 'index.aspx?wid=309&scene=church';
	});
	$("#btvr").on('click', function () {
		$("#workdetail").attr("src", "");
		$("#authordetail").attr("src", "");
		$(".icon_back").fadeOut(100);
		$(".weui-tabbar").fadeOut(100);
		$(".tabbar_author").removeClass("tabbar_author_on");
		$(".tabbar_work").removeClass("tabbar_work_on");
		maincontent.slideTo(0);
	});
	$("#btwork").on('click', function () {
		$(".icon_back").fadeIn(100);
		$(".weui-tabbar").fadeIn(100);
		$(".tabbar_work").addClass("tabbar_work_on");
		$(".tabbar_author").removeClass("tabbar_author_on");
		maincontent.slideTo(1);
	});
	$("#btauthor").on('click', function () {
		$(".icon_back").fadeIn(100);
		$(".weui-tabbar").fadeIn(100);
		$(".tabbar_work").removeClass("tabbar_work_on");
		$(".tabbar_author").addClass("tabbar_author_on");
		maincontent.slideTo(2);
	});
	$(".bottom_thumb-wrap").on('click', ".swiper-slide-thumb-active", function () {
		bottom_albums.slideTo($(this).attr("data-id"));
		control.goto($(this).attr("data-groupid"), $(this).attr("data-itemid"));
	});
	$(".bottom_icon_device").on('click', function () {
		$(".bottom_icon_device").toggleClass("bottom_icon_fade");
		if ($(".bottom_icon_device").hasClass("bottom_icon_fade")) {
			control.disableOrient();
		}
		else {
			control.enableOrient();
		}
	})
	$(".left_menu").on('click', '.content', function () {
		$(".content").removeClass("content_on");
		$(this).addClass("content_on");
		close_leftmenu();
		bottom_albums.slideTo($(this).attr("data-id"), 200);
	});
	var isopen = false;
	$(".bottom_left").on('click', ".bottom_icon_album", function () {
		$(".bottom-content").fadeIn(0);
		isopen = true;
		anime({
			targets: '.bottom_thumb',
			translateY: 0,
			easing: 'linear',
			delay: 0,
			duration: 200
		});
		$(this).addClass("bottom_icon_album2").removeClass("bottom_icon_album");
	});

	function close_leftmenu() {
		$("#leftmenu_mask").fadeOut(100);
		anime({
			targets: '.left_menu',
			translateX: -250,
			easing: 'linear',
			delay: 0,
			duration: 300
		});
	}
	$(".bottom_left").on('click', ".bottom_icon_album2", function () {
		isopen = false;
		anime({
			targets: '.bottom_thumb',
			translateY: 120,
			easing: 'linear',
			delay: 0,
			duration: 300,
			complete: function (anim) {
				$(".bottom-content").fadeOut(0);
			}
		});
		$(this).addClass("bottom_icon_album").removeClass("bottom_icon_album2");
	});
	$('.bottom_icon_hiden').on('click', function () {
		if (isopen) {
			anime({
				targets: '.bottom_thumb',
				translateY: 120,
				easing: 'linear',
				delay: 0,
				duration: 100,
				complete: function (anim) {
					$(".bottom-content").fadeOut(0);
				}
			});
			$(".bottom_icon_album2").addClass("bottom_icon_album").removeClass("bottom_icon_album2");
			anime({
				targets: '.bottom',
				translateY: 90,
				easing: 'linear',
				delay: 100,
				duration: 500
			});
		}
		else {
			anime({
				targets: '.bottom',
				translateY: 90,
				easing: 'linear',
				delay: 0,
				duration: 500
			});
		}

		$(".bottom_icon_show").delay(600).fadeIn(300);
	})
	$(".bottom_icon_show").on('click', function () {
		$(".bottom_icon_show").fadeOut(0);
		anime({
			targets: '.bottom',
			translateY: 0,
			easing: 'linear',
			delay: 0,
			duration: 500
		});
	})
	$("#left_hide").on('click', function () {
		close_leftmenu();
	});
	$("#about").on('click', function () {
		$("#infomation").fadeIn(100);
	});
	$("#info_close").on('click', function () {
		$("#infomation").fadeOut(100);
	});

	$("#menu").on('click', function () {
		$("#leftmenu_mask").fadeIn(100);
		anime({
			targets: '.left_menu',
			translateX: 0,
			easing: 'linear',
			delay: 0,
			duration: 200
		});
	});
	$("#leftmenu_mask").on('click', function () {
		close_leftmenu();
	});
});
